<template>
    <view>
        <view class="font cash_font">
            <form @reset="formReset" @submit="formSubmit" :reportSubmit="true">
                <view class="cash">
                    <view class="cash_left">可提现金额：¥{{ yjdata.ktxyj }}</view>
                </view>
                <view class="cash_box">
                    <view class="cash_left">提现金额</view>
                    <view class="cash_money">
                        ¥
                        <input @input="bindblur" class="cash_box_text" name="money" type="number" value="0" />
                    </view>
                </view>
                <view class="cash_style">
                    <view class="cash_style_title">提现方式</view>
                    <view class="">
                        <view @tap="check2" class="stylewei">
                            <view class="stylewei_left">
                                <image class="stylewei_img2" mode="aspectFill" src="./static/distribution/weixin.png"></image>
                                <view class="stylewei_text">提现到微信</view>
                            </view>
                            <icon :color="color" size="20" type="success" v-if="hidden4 == true"></icon>
                        </view>
                        <view :class="'cash_style3 ' + (cash_zhi == false ? ' cash_zhi' : '')">
                            <view :class="'cash_style2 ' + (cash_zhi2 == false ? ' cash_zhi2' : '')">
                                <view class="cash_write">
                                    <view class="write_left">姓名</view>
                                    <input class="write_inp" maxlength="-1" name="name" placeholder="请输入姓名" placeholderStyle="color:#ccc;" type="text" />
                                </view>
                                <view class="cash_write">
                                    <view class="write_left">联系电话</view>
                                    <input class="write_inp" maxlength="-1" name="account_number" placeholder="请填写联系电话" placeholderStyle="color:#ccc;" type="number" />
                                </view>
                                <view class="cash_write" style="border-bottom: none">
                                    <view class="write_left">确认电话</view>
                                    <input class="write_inp" maxlength="-1" name="account_number_two" placeholder="请确认联系电话" placeholderStyle="color:#ccc;" type="number" />
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
                <view class="read">
                    <checkbox-group name="checkbox">
                        <checkbox color="#ff6161" style="zoom: 80%" value="1"></checkbox>
                    </checkbox-group>
                    <view>
                        我已阅读并同意
                        <text @tap="lookck" class="readfont">《佣金提现协议》</text>
                    </view>
                </view>
                <view class="cash_btn">
                    <button class="cash_btnin1" formType="submit" :style="'background:' + color">提现</button>
                </view>
                <view class="cash_info">
                    <view>详细说明</view>
                    <view>提现门槛为{{ fxset.tx_money }}元</view>
                    <view v-if="system.tx_sxf > 0">提现手续费为{{ fxset.tx_rate }}%</view>
                    <view v-if="sxf != null">本次提现将扣除手续费¥{{ sxf }}</view>
                    <view v-if="sj_cost != null">本次提现实际到账金额¥{{ sj_cost }}</view>
                </view>
            </form>
        </view>

        <!-- parse <template is="xytemp" :data="fwxy:fwxy,xymc:xymc,xynr:xynr"></template> -->
        <block name="xytemp">
            <view class="zhezhao" v-if="!fwxy"></view>
            <view :class="'kcrzxy ' + (fwxy ? '' : 'active')">
                <view class="kcrzxyhd">{{ xymc }}</view>
                <scroll-view scrollY class="kcrzxybd" style="height: 600rpx">
                    <rich-text :nodes="xynr"></rich-text>
                </scroll-view>
                <view @tap="queren" class="queren">确定</view>
            </view>
        </block>
    </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
import gettel from '@/ymq_canyino2o/dist/gettel/index';
var app = getApp();
export default {
    components: {
        cardlist,
        gettel
    },
    data() {
        return {
            hidden3: false,
            hidden4: true,
            button: true,
            cash_zhi2: false,
            cash_zhi: false,
            tx_cost: 0,
            sj_cost: 0,
            fwxy: true,
            xymc: '佣金提现协议',
            xynr: '',

            yjdata: {
                ktxyj: ''
            },

            fxset: {
                tx_money: '',
                tx_rate: ''
            },

            seller_id: '',
            sxf: '',
            color: '',

            system: {
                tx_sxf: 0
            }
        };
    },
    onLoad: function (t) {
        app.globalData.setNavigationBarColor(this);
        var that = this;
        var e = uni.getStorageSync('users').id;
        app.globalData.util.request({
            url: 'entry/wxapp/MyCommission',
            cachetime: '0',
            data: {
                user_id: e
            },
            success: function (t) {
                console.log(t.data);
                that.setData({
                    yjdata: t.data
                });
            }
        });
        app.globalData.util.request({
            url: 'entry/wxapp/CheckRetail',
            cachetime: '0',
            success: function (t) {
                console.log('CheckRetail', t.data);
                that.setData({
                    fxset: t.data,
                    xynr: t.data.tx_details
                });
            }
        });
        that.setData({
            seller_id: t.seller_id
        });
    },
    onReady: function () {},
    onShow: function () {
        //console.log(this);
    },
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    methods: {
        lookck: function () {
            this.setData({
                fwxy: false
            });
        },

        queren: function () {
            this.setData({
                fwxy: true
            });
        },

        bindblur: function (t) {
            var a = Number(this.fxset.tx_rate);
            var e = Number(t.detail.value);
            var o = e * (a / 100);
            var s = e - o;
            s = s.toFixed(2);
            o = o.toFixed(2);
            this.setData({
                tx_cost: e,
                sxf: o,
                sj_cost: s
            });
        },

        formSubmit: function (t) {
            var that = this;
            console.log(t);
            console.log(that);
            var e = uni.getStorageSync('users').id;
            var o = Number(that.fxset.tx_money);
            var s = that.sj_cost;
            var n = (that.sxf, Number(that.yjdata.ktxyj));
            var i = t.detail.value.name;
            var c = that.tx_cost;
            var u = t.detail.value.account_number;
            var l = t.detail.value.account_number_two;
            var d = t.detail.value.checkbox.length;
            console.log('zd_money', o, 'sj_cost', s, 'ktxyj', n, 'tx_cost', c, i, u, l, 'user_id', e, d);
            var r = '';
            if ('' == c || c <= 0) {
                r = '请输入提现金额';
            } else {
                if (n < c) {
                    r = '不能超过可提现金额';
                } else {
                    if (c < o) {
                        r = '没有到提现门槛';
                    } else {
                        if ('' == i) {
                            r = '请输入姓名';
                        } else {
                            if ('' == u) {
                                r = '请输入联系电话';
                            } else {
                                if ('' == l) {
                                    r = '请再次输入联系电话';
                                } else {
                                    if (u != l) {
                                        r = '联系电话不一致，请重新输入';
                                    } else {
                                        if (0 == d) {
                                            r = '阅读并同意《佣金提现协议》';
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ('' != r) {
                uni.showModal({
                    title: '温馨提示',
                    content: r
                });
            } else {
                uni.showLoading({
                    title: '加载中',
                    mask: true
                });
                app.globalData.util.request({
                    url: 'entry/wxapp/SaveYjtx',
                    data: {
                        user_id: e,
                        user_name: i,
                        account: u,
                        tx_cost: c,
                        sj_cost: s
                    },
                    success: function (t) {
                        console.log(t);
                        if (1 == t.data) {
                            uni.showToast({
                                title: '发起提现申请'
                            });
                            setTimeout(function () {
                                uni.navigateBack({
                                    delta: 1
                                });
                            }, 1000);
                        }
                    }
                });
            }
        },

        inform: function (t) {
            uni.navigateTo({
                url: 'inform?status=2'
            });
        },

        formReset() {
            console.log('占位：函数 formReset 未声明');
        },

        check2() {
            console.log('占位：函数 check2 未声明');
        }
    }
};
</script>
<style>
@import './tixian.css';
</style>
